<?php

declare(strict_types=1);

namespace app\shop\controller;

use app\shop\controller\Base;
use app\model\Column;
use think\facade\Request;
use app\model\Goods;
use app\model\GoodsCat;

/**
 * @name 首页类
 */
class Index extends Base
{
    /**
     * @name 首页栏目
     */
    public function index()
    {
        if (request()->isPost()) {
            $res = Column::find('1');
            $res['column_img'] = Request::domain() . $res['column_img'];
            return json(['code' => 0, 'msg' => '操作成功', 'data' => $res]);
        };
    }
    /**
     * @name 商品类型
     */
    public function goodscat()
    {
        if (request()->isPost()) {
            $res = GoodsCat::list();
            return json(['code' => 0, 'msg' => '操作成功', 'data' => grades($res)]);
        }
    }

    /**
     * @name 热门类型
     */
    public function hot_cat()
    {
        $cat = GoodsCat::list([['is_hot', '=', '1'], ['is_show', '=', '1']]);
        foreach ($cat as $k => $v) {
            if ($k < 4) {
                $v['son'] = Goods::wherefive([['cat_id', '=', $v['id']], ['is_show', '=', '1'], ['is_hot', '=', '1']]);
                $arr[] = $v;
            }
        }
        if (request()->isPost()) {
            return json(['code' => 0, 'msg' => '操作成功', 'data' => $arr]);
        }
    }

    /**
     * @name 更多商品
     */
    public function mores()
    {
        if (request()->isPost()) {
            $page = Request::param('page');
            $list = Goods::move((int)$page);
            return json(['code' => 0, 'msg' => '操作成功', 'data' => $list]);
        }
    }
}
